/*
 * Copyright 2016-2018 TVI Go Easy.
 * Created on 2018/1/29 14:34
 */
package com.tvi.cloud.organization.service;

import com.tvi.cloud.organization.message.SimpleSourceBean;
import com.tvi.cloud.organization.model.Organization;
import com.tvi.cloud.organization.repository.OrganizationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 请在此写下该类的说明
 *
 * @author mechanic
 */
@Service
public class OrganizationService {

    private final OrganizationRepository organizitionRepository;
    private final SimpleSourceBean simpleSourceBean;

    @Autowired
    public OrganizationService(OrganizationRepository organizitionRepository
            , SimpleSourceBean simpleSourceBean
    ) {
        this.organizitionRepository = organizitionRepository;
        this.simpleSourceBean = simpleSourceBean;
    }

    public Organization findOne(String id) {
        return this.organizitionRepository.findOne(id);
    }

    public Organization save(Organization organizition) {
        Organization org = this.organizitionRepository.save(organizition);
        simpleSourceBean.publishOrgChange("UPDATE", org.getId());
        return org;
    }

    public void delete(String id) {
        this.organizitionRepository.delete(id);
        simpleSourceBean.publishOrgChange("DELETE", id);
    }
}
